// pages/results/results.js
var app = getApp();
Page({
  data: {
    totalScore: null, // 分数
    wrongList: [], // 错误的题数
    chooseValue: [], // 选择的答案
    remark: ["好极了！你很棒棒哦", "哎哟不错哦", "别灰心，继续努力哦！"], // 评语
  },
  onLoad: function (options) {
    console.log(options);
    console.log('标题二', options.testId);
    wx.setNavigationBarTitle({ title: options.testId }) // 动态设置导航条标题

    const { NAME } = options
    const { CONSUMER_COMPANY } = options
    const { STUDENT_PHONE } = options
    let wrongList = JSON.parse(options.wrongList);
    let chooseValue = JSON.parse(options.chooseValue);
    console.log('ren结果', NAME);
    console.log('ren结果', STUDENT_PHONE);
    console.log('ren结果', CONSUMER_COMPANY);
    console.log('分数', options.totalScore);



    this.setData({
      totalScore: options.totalScore,
      wrongList: wrongList,
      chooseValue: chooseValue,
      STUDENT_PHONE: STUDENT_PHONE,
      CONSUMER_COMPANY: CONSUMER_COMPANY,
      NAME: NAME,
      openid: app.globalData.openid
    })
    console.log(this.data.chooseValue);
    console.log(this.data.openid);

  },
  // 查看错题
  // toView: function () {

  // },
  // 返回首页
  toIndex: function () {

    wx.request({
      url: app.globalData.interface+'/shangLuoWork/API_1017_saveConsumer',
      method: 'POST',
      data: {
        CONSUMER_ACHIEVEMENT: this.data.totalScore,
        CONSUMER_PHONE: this.data.STUDENT_PHONE,
        CONSUMER_COMPANY: this.data.CONSUMER_COMPANY,
        CONSUMER_OPENID: this.data.openid,
        CONSUMER_NAME: this.data.NAME
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res);
        console.log(res.data.data);

        //是否领取成功弹框
        if (res.data.data.encourage != 'true') {

          wx.navigateTo({
            url: '../../pages/home/home',
          })
        } else {

          wx.navigateTo({
            url: '../../pages/home/home'
          })

        }
      }
    })
  }
})